﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KabiManagementWeb.Models;
using System.Globalization;
namespace KabiManagementWeb.Controllers
{
    public class PenaltyDetailsController : Controller
    {
        private KBManagementDataContext context = DBUtils.GetContext(DBUtils.DBType.Local);
        private void GetViewIndexData()
        {

            ViewData["time"] = new SelectList(new List<SelectListItem> { 
                 new SelectListItem { Text = "Tất cả", Value = "all" },
                new SelectListItem { Text = "Trong ngày", Value = "day" },
                new SelectListItem { Text = "Trong Tuần", Value = "week" } ,
                new SelectListItem { Text = "Trong Tháng", Value = "month" }}, "Value", "Text");
        }
        //
        // GET: /PenaltyDetails/

        public ActionResult Index()
        {
            GetViewIndexData();
            return View(context.Penalty_Details);
        }
        [HttpPost]
        public ActionResult Index(string time)
        {
            GetViewIndexData();
            if (time == "day")
            {
                return View(context.Penalty_Details.Where(x => x.PenaltyDate.Value.Date == DateTime.Now.Date));
            }

            if (time == "week")
            {
                CultureInfo ciCurr = CultureInfo.CurrentCulture;
                return View(context.Penalty_Details.ToList().Where(x =>ciCurr.Calendar.GetWeekOfYear(x.PenaltyDate.Value, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) == ciCurr.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)));

            }
            if (time == "month")
            {
                return View(context.Penalty_Details.Where(x => x.PenaltyDate.Value.Month == DateTime.Now.Month));
            }
            else {
                return View(context.Penalty_Details);
            }




        }

    }
}
